package util;

import entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Component;

@Component
public class RedisValue {
    @Autowired
    private static RedisTemplate redisTemplate;

    public static User getUserByRedis(String key) {
        User user = new User();
        ValueOperations<String, User> operations = redisTemplate.opsForValue();
        Boolean hasKey = redisTemplate.hasKey(key);
        if (hasKey) {
            user = operations.get(key);
        }
        return user;
    }
}
